#pragma once
#include "vector3.h"
#include <Windows.h>
#include <stdio.h>

#include <GL\GL.h>
#include <GL\GLU.h>
#include <GL\glut.h>

#define PI 3.14
#define ToRad PI / 180

class DrawTools
{
public:
	///Draws a line between two 3d cordinate poitns, with a color and width specified
	static void drawLine( vector3 p1, vector3 p2, vector3 color, double width = 1 ){
		toggleLine( true, width );

		glColor3d( color.x, color.y, color.z );
		glLineWidth( width );
		glBegin( GL_LINES );
			glVertex3d( p1.x, p1.y, p1.z );
			glVertex3d( p2.x, p2.y, p2.z );
		glEnd();

		//turn off line width mod
		toggleLine();
	}

	static void drawQuad( vector3 p1, vector3 p2, vector3 p3, vector3 p4, vector3 color ){
		glColor3d( color.x, color.y, color.z );
		glBegin( GL_QUADS );
			glVertex3d( p1.x, p1.y, p1.z );
			glVertex3d( p2.x, p2.y, p2.z );
			glVertex3d( p3.x, p3.y, p3.z );
			glVertex3d( p4.x, p4.y, p4.z );
		glEnd();
	}

	static void drawCircle( vector3 center, double radius, vector3 color) {
		glBegin( GL_TRIANGLE_FAN );
			glColor3d( color.x, color.y, color.z );
			glVertex3d( center.getX() , center.getY(), center.getZ());
			for (int i=0; i < 360; i++)
			{
				float degInRad = i  ;
				glVertex3d(	center.getX() + cos(degInRad) * radius,
							center.getY() + sin(degInRad) * radius,
							center.getZ());
			}
		glEnd();
	}

	static void drawCurvePoints( vector3 * points, int counter, vector3 color, double linewidth = 1 ){
		
		//turn on line widths
		toggleLine( true, linewidth );

		//set color
		glColor3f( color.x, color.y, color.z );

		//drawShape
		glBegin( GL_LINES );
			vector3 curVector = points[0];
			glVertex3d( points[0].getX(), points[0].getY(), points[0].getZ() );
			for( int i = 0; i < counter; i++ ){
					curVector = points[ i ];
					glVertex3d( curVector.getX(), curVector.getY(), curVector.getZ() );
					curVector = points[ i++ ];
					glVertex3d( curVector.getX(), curVector.getY(), curVector.getZ() );
			}
		glEnd();

		//turn off line width mod
		toggleLine();
	}

	static void drawPolyGon( vector3 * points, int counter, vector3 color){
		glBegin( GL_POLYGON );
			glColor3f( color.x, color.y, color.z );
			for( int i = 0; i < counter; i++ ){
				glVertex3d( points[i].getX(), points[i].getY(), points[i].getZ()); 
			}
		glEnd();
	} 

	static void toggleLine( bool turnOn = false, int width = 1 ){
		if( turnOn ){
			glEnable( GL_LINE_SMOOTH );
			glLineWidth( width );
		}else{
			glDisable( GL_LINE_SMOOTH );
			glLineWidth( 1 );
		}
	}

	static void drawText( vector3 loc, char * whattoSay, vector3 font_color ){
		char *c;
		glLoadIdentity();
		glColor3f( font_color.getX(), font_color.getY(), font_color.getZ());
		glEnable(GL_LINE_SMOOTH);
		glRasterPos3f(loc.getX(), loc.getY(), loc.getZ());
		for (c=whattoSay; *c != '\0'; c++) {
			 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *c);
		}
	}
};

